﻿namespace Papyrus.Web.Tests.Controllers
{
    using System.Web.Mvc;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Moq;
    using Papyrus.Web.Controllers;
    using Papyrus.Web.Models;
    using Papyrus.Web.Models.Entities;

    [TestClass]
    public class CustomerControllerFixture
    {
        [TestMethod]
        public void ShouldRenderNewViewOnCreateAction()
        {
            var controller = new CustomerController();

            var result = controller.Create();

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual("Create", ((ViewResult)result).ViewName);
        }

        [TestMethod]
        public void ShouldSaveNewCustomer()
        {
            var customerViewModel = new CustomerViewModel();
            customerViewModel.Address = "Peru 2010";
            customerViewModel.DocumentId = "12345678";
            customerViewModel.Firstname = "Jose";
            customerViewModel.Lastname = "Perez";
            customerViewModel.PhoneNumber1 = "666666";
            customerViewModel.PhoneNumber2 = "555555";
            var mockRepository = new Mock<ICustomerRepository>();
            mockRepository.Setup(r => r.Save(It.Is<Customer>(l => l.Address == customerViewModel.Address && l.DocumentId == customerViewModel.DocumentId
                        && l.Firstname == customerViewModel.Firstname && l.Lastname == customerViewModel.Lastname && l.PhoneNumber1 == customerViewModel.PhoneNumber1
                        && l.PhoneNumber2 == customerViewModel.PhoneNumber2))).Verifiable();
            var controller = new CustomerController(mockRepository.Object);

            var result = controller.Save(customerViewModel);

            mockRepository.Verify();
        }
    }
}
